package com.wanke.base.dto;


import java.util.List;

/**
 * JSON结果返回对象
 *
 * @author liuronglei
 * @desc JSON结果返回对象定义
 */
public class ResultObject<T> {
    private T results;
    private Integer page;
    private Integer size;
    private Long totalCount;
    private Integer totalPages;
    private int errorCode;
    private String errorMsg;

    public ResultObject() {
    }

    public ResultObject(T results) {
        if (results instanceof Iterable) {
            this.results = results;
            this.page = 0;
            this.totalCount = (long) ((List) results).size();
            this.totalPages = 1;
            this.size = this.totalCount.intValue();
        } else {
            this.results = results;
            this.page = 0;
            this.totalCount = 0L;
            this.totalPages = 0;
            this.size = 0;
        }
    }

    public ResultObject(int errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public ResultObject(T results, int page, int size, Long totalCount, int totalPages) {
        this.results = results;
        this.page = page;
        this.size = size;
        this.totalCount = totalCount;
        this.totalPages = totalPages;
    }

    public T getResults() {
        return results;
    }

    public void setResults(T results) {
        this.results = results;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }
}
